// generated 2005/8/22 19:17:02 CST by xihels@163.com
//


#if defined __GNUC__ && __GNUC__ < 3
#error This program will crash if compiled with g++ 2.x
// see the dynamic_cast bug in the gtkmm FAQ
#endif //
#include "config.h"
#include <gtkmmconfig.h>
#if GTKMM_MAJOR_VERSION==2 && GTKMM_MINOR_VERSION>2
#define GMM_GTKMM_22_24(a,b) b
#else //gtkmm 2.2
#define GMM_GTKMM_22_24(a,b) a
#endif //
#include "Smiley.h"
#include <gdk/gdkkeysyms.h>
#include <gtkmm/accelgroup.h>
#include <gdkmm/pixbufloader.h>
#include <gtkmm/image.h>
#include <gtkmm/button.h>
#include <gtkmm/table.h>

#include "MsgPage.h"
#include "MsgBox.h"

#include "pixmaps.h"

Smiley::Smiley() : 
    page(NULL)
{  
    Gtk::Window* smiley = this;
    gmm_data = new GlademmData(get_accel_group());
    Gtk::Table* table = Gtk::manage(new class Gtk::Table(10, 10, true));
    
    table->set_row_spacings(0);
    table->set_col_spacings(0);

    Gtk::Image* image = NULL;
    Gtk::Button* button = NULL;

    int x;
    int y;
    int index;
    for (int i = 0; i < 96; i++) {
	image = getSmil(i);
	image->set_alignment(0.5,0.5);
	image->set_padding(0,0);
	button = Gtk::manage(new class Gtk::Button());
	button->set_relief(Gtk::RELIEF_NONE);
	button->add(*image);
	x = i % 10;
	y = i / 10;
	table->attach(*button, x, x + 1, y, y + 1,
		Gtk::AttachOptions(), Gtk::AttachOptions(), 0, 0);
	button->signal_clicked().connect(
		sigc::bind<int>(
		sigc::mem_fun(*this, &Smiley::on_smiley_clicked), i), false);
	_tooltips.set_tip(*button, SmileyMap::getSmilCode(i), "");
	//image->show();
	//button->show();
    }

    smiley->set_title("表情");
    smiley->property_window_position().set_value(Gtk::WIN_POS_MOUSE);
    smiley->set_resizable(false);
    smiley->set_type_hint(Gdk::WINDOW_TYPE_HINT_TOOLBAR);
    smiley->add(*table);
    table->show_all();
}

void Smiley::on_smiley_clicked(int index)
{
    hide();
    if (NULL != page) {
	page->insertSmiley(index);
	page = NULL;
    }
}

Smiley::~Smiley()
{  
    delete gmm_data;
}
